<!-- 政策法规 -->
<template>
  <div>
    <div class="news-cells">
      <!-- <van-pull-refresh v-model="isLoading" @refresh="onRefresh" success-text="刷新成功"> -->
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="newLoad"
      >
        <div
          class="news-cell"
          v-for="(item, i) in policy"
          :key="i"
          @click="href('/NewsDetail', item.id)"
        >
          <!-- <img class="news-img" :src="item.picaddress" alt /> -->
          <div>
            <div class="news-text">{{ item.title }}</div>
            <!-- <van-row :gutter="20">
                      <van-col :span="8" v-for="(subitem, i) in item.img" :key="i">
                        <img :src="baseURL + subitem.img" alt />
                      </van-col>
              </van-row>-->
            <div class="news-attr">
              <div>
                {{ item.institution }}
                <div>阅读 {{ item.djl }}</div>
              </div>

              <div>{{ item.createTime }}</div>
            </div>
          </div>
        </div>
      </van-list>
      <!-- </van-pull-refresh> -->
    </div>
  </div>
</template>

<script>
import { baseURL } from "../../assets/js/config";
import { troubleShooting } from "../../assets/js/api/user";
import { getNewaLength } from "../../assets/js/api/News";
// 引入接口api
// import { advertising, getNewaLength } from "../../assets/js/api/News";
export default {
  name: "PolicySupport",
  data() {
    return {
      policy: [], // 政策法规
      loading: false,
      finished: false,
      // isLoading: false, // 刷新按钮
      extent: "", // 咨询接口总长度
      pagination: 1 // 需要查询的长度
    };
  },
  mounted() {
    this.baseURL = baseURL;
    getNewaLength(1).then(res => {
      // console.log(res);
      this.extent = res.data;
    });
  },
  methods: {
    href(url, id) {
      this.$router.push({ path: url + "/" + id });
    },

    newLoad() {
      // 政策法规
      let pageSize = 10;
      let pageNum = this.pagination;
      this.pagination++;
      let obj = {
        pageSize: pageSize,
        pageNum: pageNum,
        type: "1"
      };
      // alert("没通过");
      troubleShooting(obj).then(res => {
        // alert("通过");
        let list = res.data;
        console.log(res);
        for (let i = 0; i < list.length; i++) {
          this.policy.push(list[i]);
          // if (list[i].lb === "2") {
          //   this.policy.push(list[i]);
          // }
        }
        // 加载状态结束
        this.loading = false;

        // 数据全部加载完成
        // 停止行业资讯
        if (this.policy.length >= this.extent) {
          this.finished = true;
        }
      });
    }
    // 刷新按钮
    // onRefresh() {
    //   this.$router.go(0);
    // }
  }
};
</script>

<style></style>
